package cn.webestar.scms.mybatisplus.function;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

public class CountMethod extends AbstractMethod {

    protected CountMethod(String methodName) {
        super(methodName);
    }

    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
        final String sql = "<script>select count(*) from %s</script>";
        final String sqlResult = String.format(sql, tableInfo.getTableName());
        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sqlResult, modelClass);
        return this.addSelectMappedStatementForOther(mapperClass, "count", sqlSource, Integer.class);
    }

}
